<template>
<view>
<view class="setting_head">
	<view class="head_pic">
		<view class="lefticon">
			<image :src="userinfo.avatar" @click="goGeneraluserinfo"></image>
			<view @click="goGeneraluserinfo">
				<text class="setting_username">{{ userinfo.nickname }}</text>
				<text class="setting_username2">快狗号:{{ userinfo.account }}</text>
			</view>
		</view>
		<view class="righticon">
			<image class="listright" src="/static/erweima.png" @click="goGeneralMycode"></image>
			<image class="listright" src="/static/images/next.png" @click="goGeneraluserinfo"></image>
		</view>
	</view>
	
</view>

<view class="setting_list">
	<view class="setting_listContent" @tap="goGeneralMoney">
		<view class="icontext">
			<image src="/static/myicon/zhifu.png" mode="" class="myiconimg"></image>
			<text>零钱</text>
		</view>
		<image class="list_right" src="/static/images/next.png"></image>
	</view>
</view>
<view class="setting_list">
	<view class="settinglist" @tap="goGeneralWechat">
		<view class="icontext">
			<image src="/static/myicon/pengyouquan.png" mode="" class="myiconimg"></image>
			<text>朋友圈</text>
		</view>
		<image class="list_right" src="/static/images/next.png"></image>
	</view>
	<view class="settinglist" @tap="goMessage">
		<view class="icontext">
			<image src="/static/lingdang.png" mode="" class="myiconimg"></image>
			<text>系统消息</text>
		</view>
		<image class="list_right" src="/static/images/next.png"></image>
	</view>
	<view class="settinglist" @tap="goGeneralMycode">
		<view class="icontext">
			<image src="/static/myicon/myerweima.png" mode="" class="myiconimg"></image>
			<text>我的二维码</text>
		</view>
		<image class="list_right" src="/static/images/next.png"></image>
	</view>
	
	<view class="settinglist" @tap="goGeneralProfit">
		<view class="icontext">
			<image src="/static/myicon/shouyi.png" mode="" class="myiconimg"></image>
			<text>积分明细</text>
		</view>
		<image class="list_right" src="/static/images/next.png"></image>
	</view>
<!-- 	<view class="settinglist" @tap="goGeneralYHK">
		<view class="icontext">
			<image src="/static/myicon/yinhangka.png" mode="" class="myiconimg"></image>
			<text>我的银行卡</text>
		</view>
		<image class="list_right" src="/static/images/next.png"></image>
	</view> -->
</view>

<view class="setting_list" style="margin-bottom: 100px;">
	<view class="setting_listContent" @tap="goGeneralSetting">
		<view class="icontext">
			<image src="/static/myicon/shezhi.png" mode="" class="myiconimg"></image>
			<text>设置</text>
		</view>
		<image class="list_right" src="/static/images/next.png"></image>
	</view>
	<view class="settinglist" @tap="gokefu" style="margin-top: 6px;">
		<view class="icontext">
			<image src="/static/kefu.png" mode="" class="myiconimg"></image>
			<text>客服</text>
		</view>
		<image class="list_right" src="/static/images/next.png"></image>
	</view>
</view>
<!-- <view class="setting_list">
	<view class="setting_listContent" @tap="logout">
		<text class="setting_redtext">退出登录</text>
	</view>
</view> -->

<view :class="isIPX?'chatRoom_tab_X':'chatRoom_tab'">
	<view class="tableBar" @tap="tab_chat">
		<view v-if="unReadSpotNum > 0 || unReadSpotNum == '99+'" :class="'em-unread-spot ' + (unReadSpotNum == '99+'?'em-unread-spot-litleFont':'')">{{ unReadSpotNum }}</view>
		<image :class="unReadSpotNum > 0 || unReadSpotNum == '99+'? 'haveSpot': ''" src="/static/bottom/xiaoxi.png"></image>
		<text style="font-size: 13px;">聊天</text>
	</view>

	<view class="tableBar" @tap="tab_contact">
		<view v-if="unReadTotalNotNum > 0" class="em-unread-spot">{{ unReadTotalNotNum }}</view>
		<image :class="unReadTotalNotNum > 0 ? 'haveSpot': ''" src="/static/bottom/tongxunlu.png"></image>
		<text style="font-size: 13px;">通讯录</text>
	</view>
	
	<!-- <view class="tableBar" @tap="tab_notification">
		<image :class="unReadTotalNotNum > 0 ? 'haveSpot': ''" src="/static/bottom/faxian.png"></image>
		<text style="font-size: 13px;">发现</text>
	</view> -->
	
	<view class="tableBar">
		<image src="/static/bottom/myred.png"></image>
		<text class="activeText" style="font-size: 13px;">我的</text>
	</view>
</view>
</view>
</template>

<script>
let WebIM = require("../../utils/WebIM")["default"];
let disp = require("../../utils/broadcast");

export default {
  data() {
    return {
      yourname: "",
      messageNum: 0,
      unReadSpotNum: 0,
      unReadNoticeNum: 0,
      unReadTotalNotNum: 0,
      isIPX: false,
	  userinfo:'',//用户信息
	  clickshow:true 
    };
  },

  components: {},
  props: {},
  onLoad: function (option) {
    let me = this;
    this.setData({
      yourname: uni.getStorageSync("myUsername")
    }); //监听加好友申请

    disp.on("em.subscribe", function () {
      me.setData({
        messageNum: getApp().globalData.saveFriendList.length,
        unReadTotalNotNum: getApp().globalData.saveFriendList.length + getApp().globalData.saveGroupInvitedList.length
      });
    }); //监听未读“聊天”

    disp.on("em.unreadspot", function () {
      me.setData({
        unReadSpotNum: getApp().globalData.unReadMessageNum
      });
    }); //监听未读“通知”数

    disp.on("em.invite.joingroup", function (count) {
      me.setData({
        unReadNoticeNum: getApp().globalData.saveGroupInvitedList.length,
        unReadTotalNotNum: getApp().globalData.saveFriendList.length + getApp().globalData.saveGroupInvitedList.length
      });
    });
  },

  onShow() {
	this.GetUserInfo();
    this.setData({
      messageNum: getApp().globalData.saveFriendList.length,
      unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
      unReadNoticeNum: getApp().globalData.saveGroupInvitedList.length,
      unReadTotalNotNum: getApp().globalData.saveFriendList.length + getApp().globalData.saveGroupInvitedList.length
    });

    if (getApp().globalData.isIPX) {
      this.setData({
        isIPX: true
      });
    }
  },

  methods: {
	  //用户详细信息
	  goGeneraluserinfo(){
		  uni.navigateTo({
		  	url:'/pages/setting/userinfo'
		  })
	  },
	  //钱包
	  goGeneralMoney(){
		  uni.navigateTo({
		  	url:"/pages/setting/money"
		  })
	  },
	  //朋友圈
	  goGeneralWechat(){
		  uni.navigateTo({
		  	url:"/pages/setting/WechatMoments"
		  })
	  },
	  goMessage(){
		uni.navigateTo({
			url:'/pages/msglist/msglist'
		})  
	  },
	  //我的二维码
	  goGeneralMycode(){
		  uni.navigateTo({
		  	url:"/pages/setting/mycode"
		  })
	  },
	  //跳转收益
	  goGeneralProfit(){
		  uni.navigateTo({
		  	url: "/pages/setting/profit"
		  })  
	  },
	  //客服
	  gokefu(){
		 uni.navigateTo({
		 	url:'/pages/help/help'
		 }) 
	  },
	  //跳转银行卡
	  goGeneralYHK(){
		uni.navigateTo({
			url: "/pages/setting/yinhangka"
		})  
	  },
	  //获取用户信息
	  GetUserInfo(){
			let _this = this
			let token = uni.getStorageSync("token")
			uni.request({
				url: this.G_base + '/api/userinfo',
				method: "GET",
				header: {
					'content-type': 'application/x-www-form-urlencoded',
					'Authori-zation': 'Bearer ' + token
				},
				success: (res) => {
					console.log(res)
					_this.userinfo = res.data.data.data
				},
				fail: (err) => {
					console.log(err)
				}
			});
	  },
    tab_contact: function () {
		let that=this;
		if(that.clickshow) {
			that.clickshow = false;
		    uni.redirectTo({
			    url: "../main/main?myName=" + uni.getStorageSync("myUsername")
		    });
			setTimeout(function () {
				that.clickshow = true;
			}, 1500)
		} else {
			//如果一直走else分支可能是你没有在页面的data下面挂载clickshow:true,不然一直都会走else
			uni.showToast({
				title:'请勿频繁点击',
				icon:'none'
			})
		}
    },
    tab_chat: function () {
		let that=this;
		if(that.clickshow) {
			that.clickshow = false;
			uni.redirectTo({
			  url: "../chat/chat"
			});
			setTimeout(function () {
				that.clickshow = true;
			}, 1500)
		} else {
			//如果一直走else分支可能是你没有在页面的data下面挂载clickshow:true,不然一直都会走else
			uni.showToast({
				title:'请勿频繁点击',
				icon:'none'
			})
		}
    },
    tab_notification: function () {
      uni.redirectTo({
        url: "../faxian/newfaxian"
      });
    },
    goGeneralSetting: function () {
      uni.navigateTo({
        url: "/pages/setting/shezhi"
      });
    },
    logout: function () {
      uni.showModal({
        title: "是否退出登录",
        success: function (res) {
          if (res.confirm) {
            WebIM.conn.close(); // uni.closeSocket()

            uni.redirectTo({
              url: "../login/login"
            });
          }
        }
      });
    }
  }
};
</script>
<style>
@import "./setting.css";
</style>